package com.xingkeduo.business.user.controller;

import com.xingkeduo.business.transformation.json.ConsumerJTO;
import com.xingkeduo.business.transformation.json.ConsumerPrivateJTO;
import com.xingkeduo.business.transformation.json.ConsumerRelateJTO;
import com.xingkeduo.business.user.domain.ConsumerDomain;
import com.xingkeduo.pojo.query.ConsumerPrivateQO;
import com.xingkeduo.pojo.query.ConsumerQO;
import com.xingkeduo.util.pojo.base.BaseController;
import com.xingkeduo.util.tool.ReturnUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用于消费者的
 *
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/3/26 21:05
 **/
@RestController
@RequestMapping("/consumer/ralate")
public class ConsumerRalateController extends BaseController {

    @Autowired
    private ConsumerDomain consumerDomain;

    /**
     * 用户绑定手机号    切换手机号也可以   切换手机号需要连绑定的手机号一起切换
     *
     * @param login:login
     * @param json:phone
     * @return : java.lang.String
     * @author : gaozifeng
     * @date : 2019/3/27 14:54
     */
    @PutMapping("/binding/{login}")
    public String binding(@PathVariable String login, @RequestBody String json) {
        returnUtil = new ReturnUtil();
        try {
            ConsumerQO consumerQO = ConsumerJTO.createQueryForBinDing(login);
            ConsumerPrivateQO privateQO = ConsumerPrivateJTO.createQueryBinDing(json);
            consumerDomain.binding(consumerQO, privateQO);
            return returnUtil.getSuccess();
        } catch (Throwable t) {
            return dealException(t, returnUtil);
        }
    }

    /**
     * 解绑手机号
     *
     * @param login:login
     * @return : java.lang.String
     * @author : gaozifeng
     * @date : 2019/3/27 15:28
     */
//    @PutMapping("/untied/{login}")
//    public String untied(@PathVariable String login) {
//        returnUtil = new ReturnUtil();
//        try {
//            ConsumerQO consumerQO = ConsumerJTO.createQueryForBinDing(login);
//            consumerDomain.untied(consumerQO);
//            return returnUtil.getSuccess();
//        } catch (Throwable t) {
//            return dealException(t, returnUtil);
//        }
//    }

    /**
     * 查询用手机号的集合
     *
     * @param :login
     * @return : java.lang.String
     * @author : gaozifeng
     * @date : 2019/3/28 15:57
     */
    @GetMapping("/list/{login}")
    public String getRelateList(@PathVariable String login) {
        returnUtil = new ReturnUtil();
        try {
            ConsumerQO consumerQO = ConsumerJTO.createQueryForBinDing(login);
            return returnUtil.getSuccess(ConsumerRelateJTO.toJson(consumerDomain.getRelateList(consumerQO)));
        } catch (Throwable t) {
            return dealException(t, returnUtil);
        }
    }

//    /**更改绑定微信
//     * @param login:
//     * @return : java.lang.String
//     * @author : gaozifeng
//     * @date : 2019/3/29 10:38
//     */
//    @PutMapping("/changelogin/{login}")
//    public String changeLogin(@PathVariable String login,@RequestBody String newlogin){
//        returnUtil = new ReturnUtil();
//        try {
//            ConsumerQO consumerQO = ConsumerJTO.createQueryForBinDing(login);
//            ConsumerQO newConsumerQO = ConsumerJTO.createQueryForBinDing(newlogin);
//            ConsumerRelateJTO.toJson(consumerDomain.changeLogin(consumerQO,newConsumerQO));
//            return returnUtil.getSuccess();
//        } catch (Throwable t) {
//            return dealException(t, returnUtil);
//        }
//    }
}
